package com.angel.architecture.initializer.injector.impl;

import java.lang.reflect.Field;

import org.apache.log4j.Logger;

import com.angel.architecture.flex.locator.ObjectLocator;
import com.angel.architecture.initializer.injector.Injector;
import com.angel.common.helpers.ReflectionHelper;

/**
 *
 * @author William
 *
 */
public class SpringDAOInjector extends Injector {

	private static final Logger LOGGER = Logger.getLogger(SpringDAOInjector.class);

	@Override
	public boolean applies(Field field) {
	    Class<?> fieldType = field.getType();
	    return ObjectLocator.contains(fieldType);
	}

	@Override
	protected void doInject(Field field, Object object) {
	    Class<?> fieldType = field.getType();
	    LOGGER.debug("Injecting dao " + fieldType.getSimpleName() + " on object " + object);
	    field.setAccessible(true);
	    Object dao = ObjectLocator.get(fieldType);
	    ReflectionHelper.setFieldValue(object, field, dao);
	}

}
